# 关键字参数是通过参数名来指定参数值的方式，调用函数时可以不按照参数定义的顺序传入参数，只要指定了正确的参数名和对应的值即可
def greet(name, age):
    """
    这个函数用于输出姓名和年龄
    :param name: 姓名参数
    :param age: 年龄参数
    :return: hello,{name}; your age is {age}
    """
    print(f'hello,{name}; your age is {age}')


# 强制使用关键字参数
def greet1(a, b, *, c):
    try:
        print(f'a = {a}; b = {b}; c = {c}')
    except Exception as e:
        print('参数错误', e)


if __name__ == '__main__':
    # 当成位置参数
    greet('cendy', 18)
    # greet(name='cendy', age=18)
    # greet(age=22, name='alice')
    # greet1(1, 2, 5)     # greet1() takes 2 positional arguments but 3 were given
    greet1(1, 2, c = 6) # a = 1; b = 2; c = 6
    # greet() # TypeError: greet() missing 2 required positional arguments: 'name' and 'age'
